<?php
/**
 * Created by PhpStorm.
 * User: Vito
 * Date: 2022/5/20
 * Time: 10:25
 */

namespace app\admin\listener\dashboard;

use app\common\ArrayObject;
use app\logic\CustomerLogic;
use app\logic\DeviceLogic;
use app\logic\FlowLogic;
use app\logic\OrderLogic;
use app\logic\UserLogic;
use app\logic\WaterCompanyLogic;
use app\logic\WaterFetcherLogic;
use app\logic\WaterworksLogic;
use app\model\Order;
use app\logic\RoomLogic;

class DashboardListener
{
    /**
     * @param $params ArrayObject
     */
    public function handle($params)
    {
        $this->getData($params);
    }

    protected function getData($params)
    {
        $user   = new UserLogic();
        $order  = new OrderLogic();
        $room   = new RoomLogic();

        $params->merge([
            'count_user'                 => $user->count(),
            'count_order'                => $order->countOrder(),
            'count_order_week'           => $order->countOrder(1, 'week'),
            'count_order_month'          => $order->countOrder(1, 'month'),
            'count_order_year'           => $order->countOrder(1, 'year'),
            'sum_order_money'            => $order->sumMoney(),
            'sum_order_money_week'       => $order->sumMoney(1, 'week'),
            'sum_order_money_month'      => $order->sumMoney(1, 'month'),
            'sum_order_money_year'       => $order->sumMoney(1, 'year'),
            'count_order_week_list'      => $order->countOrderListByDay(),
            'count_order_month_list'     => $order->countOrderListByMonth(),
            'sum_order_money_week_list'  => $order->sumMoneyListByDay(),
            'sum_order_money_month_list' => $order->sumMoneyListByMonth(),
            'order_list'                 => $order->getAll(['order' => ['id' => 'desc'], 'where' => ['type' => Order::ROOM_TYPE]]),
            'count_room'                 => $room->countRoon(),
            'count_use_room'             => $room->countRoon('use'),
            'count_lessee'               => $room->countAudit('1'),
            'count_apply'                => $room->countAudit('0'),
            'housing_list'               => $room->getHousingRoomCount()
        ]);
    }

}
